package com.example.springboothomework.dao;

import com.example.springboothomework.entity.Company;
import com.example.springboothomework.entity.vo.CompanyInfoVo;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author: chenjianhao
 * @date: 2025/6/5
 * @description: 公司Repository
 */
@Repository
public interface CompanyDao extends JpaRepository<Company,Long> , JpaSpecificationExecutor<Company> {


    /**
     * 获得所有公司的id和name
     * @return
     */
    @Query("SELECT new com.example.springboothomework.entity.vo.CompanyInfoVo(c.id, c.name) FROM Company c")
    List<CompanyInfoVo> findAllCompanyInfo();

    /**
     * 根据名称判断是否存在
     * @param name
     * @return
     */
    Boolean existsByName(String name);

    /**
     * 根据名称获取id
     * @param companyName
     * @return
     */
    @Query("SELECT c.id FROM Company c WHERE c.name = ?1")
    Long findIdByName(String companyName);
}
